#include <Eigen/Dense>
#include <iostream>
using namespace Eigen;

void test2D_views() {
  Matrix4i m = Matrix4i::Random();
  std::cout << "Hree is the matrix m:\n" << m << std::endl;
  std::cout << "Here is m.reshaped(2,8):"
            << "\n"
            << m.reshaped(2, 8) << std::endl;
}

void test1D_linear_views() {
  Matrix4i m = Matrix4i::Random();
  std::cout << "Here is the matrix m:\n" << m << std::endl;
  std::cout << "Here is m.reshaped().transpose(): \n"
            << m.reshaped().transpose() << std::endl;
  std::cout << "Here is m.reshaped<RowMajor>().transpose(): \n"
            << m.reshaped<RowMajor>().transpose() << std::endl;
}

void test_ReshapeInPlace() {
  MatrixXi m = Matrix4i::Random();
  std::cout << "Here is the matrix m:\n" << m << std::endl;
  std::cout << "Here is m.reshaped(2,8):\n" << m.reshaped(2, 8) << std::endl;
  m.resize(2, 8);
  std::cout << "Here is the matrix m after m.resize(2,8):\n" << m << std::endl;
}
void test_ReshapeInPlace2(){
    // 与reshaped不同，resize的结果取决于输入存储顺序，类似于reshaped<autoOrder>
    Matrix<int, Dynamic, Dynamic, RowMajor> m = Matrix4i::Random();
    std::cout << "Here is the matrix m:\n" << m << std::endl;
    std::cout << "Here is m.reshaped<AutoOrder>(2,8):\n" << m.reshaped<AutoOrder>(2, 8) << std::endl;
    m.resize(2, 8);
    std::cout << "Here is the matrix m after m.resize(2,8):\n" << m << std::endl;
}

int main() {
  test2D_views();
  test1D_linear_views();
  test_ReshapeInPlace();
  test_ReshapeInPlace2();
  return 0;
}